<?
require_once("class_GenericRowSerial.php");

/********************************************************************************************************/
/* This class represents one row from any table which hase non composit not autoincremented PRIMARY KEY */
/********************************************************************************************************/

class IndexName extends GenericRowSerial {

    public function IndexName($id=false) {
	parent::__construct('index_name','id',$id);
    }

    public function get_stat($time_id,$prod_sql) {
        $stat_q="SELECT
pg_relation_size(oid) AS indexsize,
pg_stat_get_numscans(oid) AS idx_scan,
pg_stat_get_tuples_returned(oid) AS idx_tup_read,
pg_stat_get_tuples_fetched(oid) AS idx_tup_fetch,
pg_stat_get_blocks_fetched(oid) AS idx_blks_fetch,
pg_stat_get_blocks_hit(oid) AS idx_blks_hit
FROM pg_class WHERE oid=".$this->get_field('obj_oid');

	$prod_sql->select_c($stat_q);

	$idx_stat_res=$prod_sql->get_row_hash();
	$ins_q="INSERT INTO index_stat VALUES (
".$this->id.",
".$time_id.",
".$idx_stat_res['idx_scan'].",
".$idx_stat_res['idx_tup_read'].",
".$idx_stat_res['idx_tup_fetch'].",
".$idx_stat_res['idx_blks_fetch'].",
".$idx_stat_res['idx_blks_hit'].")";
    $this->sql->non_select_c($ins_q);

    }


    public function print_config_table_row() {
	if (!$this->loaded) {
	    $this->load();
	}
	$string="<tr><td>".$this->database_fields['idx_name']."</td><td align=right width=5%>";
	if ($this->database_fields['is_primary'] == 't') {
	    $string.="P";
	} else {
	    $string.="n";
	}
	$string.="</td><td align=right width=5%>";
	if ($this->database_fields['is_unique'] == 't') {
	    $string.="U";
	} else {
	    $string.="n";
	}
	$string.="</td></tr>";
	return $string;
    }

    public function __toString() {
	return $this->get_field('idx_name');
    }
}

?>
